package com.xbdun.comweb.bmp.frame.view;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.boot.autoconfigure.web.ErrorViewResolver;
import org.springframework.http.HttpStatus;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.xbdun.common.api.XbdUnResult;
import com.xbdun.comweb.bmp.enums.SysEnums;
/**
 * 所有自定义错误画面基类，根据状态就可以指定跳转画面 
 * @author zhanggt
 */
public abstract class BaseErrorViewResolver implements ErrorViewResolver{
	@Override
	public ModelAndView resolveErrorView(HttpServletRequest request, HttpStatus status, Map<String, Object> model) {
		ModelAndView modeView = null;
		Object attribute = request.getAttribute(SysEnums.FROM_RESPONSE_BODY+"");
		if(null!=attribute){
			if(attribute instanceof XbdUnResult){
				modeView = new ModelAndView("error/printString");
				modeView.addObject("xbdun_msg", JSON.toJSONString(attribute));
			}
			request.removeAttribute(SysEnums.FROM_RESPONSE_BODY+"");
		}
		return modeView;
	}
}